<?php
class indexControl extends Control{
    //首页显示
    function index(){
        $_GET['site']=0;//记录当前的第一位置
        $db=K("packageview");
        $row=$db->join("packcate|user")->limit(15)->all();
        $this->assign("row", $row);
        $this->display();
    }
    //登录
    function login(){
        if(!isset($_POST['username'])||$this->session_get("username")!=''){go(__WEB__);exit();}
        if(trim($_POST['username'])==''||trim($_POST['password'])==''){echo 1;exit();}
        $db=M("user");
        $user=$db->field("uid,username,password,lenum,logintime,loginnum")->find("username='{$_POST['username']}'");
        $lenum=$db->field("uid,username,password,lenum,logintime,loginnum")->find("lenum='{$_POST['username']}'");
        if($user['password']==  md5($_POST['password'])){
            $this->session_start();
            $this->session_set("uid", $user['uid']);
            $this->session_set("username", $user['username']);
            $this->session_set("lenum", $user['lenum']);
            $this->session_set("logintime", $user['logintime']);
            $arr=array();//更新登录时间
            $arr['uid']=$user['uid'];
            $arr['loginnum']=$user['loginnum']+1;
            $arr['logintime']=time();
            $db->update($arr);
            echo 2;exit();
        }
        if($lenum['password']==  md5($_POST['password'])){
            $this->session_set("uid", $lenum['uid']);
            $this->session_set("username", $lenum['username']);
            $this->session_set("lenum", $lenum['lenum']);
            $this->session_set("logintime", $lenum['logintime']);
            $arr=array();//更新登录时间
            $arr['uid']=$lenum['uid'];
            $arr['loginnum']=$lenum['loginnum']+1;
            $arr['logintime']=time();
            $db->update($arr);
            echo 2;exit();
        }
        echo 3;
    }
    //注销
    function logout(){
        if($this->session_get("username")==''){go(__WEB__);exit();}
        $this->session_delall();
        echo 1;
    }
}